<template>
  <div class="coupon_panel">
    <div class="amount_text">
      <div class="amount_value" v-if="el.type === 1">
        <span>{{el.amount}}</span>
      </div>
      <div class="discount_value" v-else>
        <span>{{(10 - el.amount / 10).toFixed(1)}}折</span>
      </div>
      <div class="condition_value">{{el.condition ? "满" + el.condition + "元可用" : "无使用门槛"}}</div>
    </div>
    <div class="title_text">
      <div class="title_value">{{el.ticketName}}</div>
      <div
        class="expire_value"
      >有效期：{{el.startTime | dateFormat('YYYY.MM.DD')}} 至 {{el.endTime | dateFormat('YYYY.MM.DD')}}</div>
      <div class="expire_value" v-if="el.limit!=0">剩余:{{el.stock}} 剩于可领:{{remain}}</div>
      <div class="expire_value" v-else>剩余:{{el.stock}}</div>
    </div>
    <div class="title_info">
      <template v-if="el.stock>0">
        <van-button
          :loading="isLogining"
          type="primary"
          class="show_lingqu"
          v-if="this.isShow"
          @click="lingqu"
        >领取优惠券</van-button>
        <div v-else class="over">
          <img src="../../../assets/images/yinzhang.png" class="juedui">
        </div>
      </template>
      <template v-else>
        <div class="show_end">发放完毕</div>
      </template>
    </div>
  </div>
</template>
<script>
import { ELE_COUPON_CREATE } from "@/api/order";
export default {
  name: "item-coupon",
  props: {
    el: Object
  },
  computed: {},

  created() {
    this.show();
  },
  data() {
    return {
      isShow: false,
      remain: this.el.remain,
      isLogining: false
    };
  },
  methods: {
    show() {
      if (this.el.isGet === 0) {
        this.isShow = true;
      }
    },
    lingqu() {
      let that = this;
      that.isLogining = true;
      this.$reqPost(
        ELE_COUPON_CREATE,
        {
          mId: this.user.id,
          id: this.el.id
        },
        {
          hideLoading: true
        }
      ).then(res => {
        if (res.data.data) {
          if (that.remain <= 1 && that.remain != null) {
            that.isShow = false;
          } else {
            that.isShow = true;
          }
          this.$dialog
            .alert({
              message: "优惠券领取成功"
            })
            .then(() => {
              //点击确认按钮后的调用
              that.el.stock--;
              that.remain--;
              that.isLogining = false;
            });
        } else {
          location.reload();
        }
      });
    }
  },
  components: {}
};
</script>
	<style lang="scss" scoped>
.coupon_panel {
  display: flex;
  margin: 10px;
  padding: 10px;
  padding-right: 0px;
  margin-right: 0;
  position: relative;
  align-items: center;
}

.amount_text {
  flex: 1;
  padding: 10px;
  text-align: center;

  .amount_value,
  .discount_value {
    color: $red;
    font-size: 20px;
  }

  .amount_value ::before {
    content: "¥";
    font-size: 14px;
    margin-right: 3px;
  }

  .condition_value {
    color: #a1435f;
    font-size: 12px;
    margin-top: 5px;
  }
}

.title_text {
  flex: 2;
  padding: 10px 0px;
  .expire_value {
    color: gray;
    font-size: 12px;
    margin-top: 5px;
  }
  .status_value {
    text-align: right;
    font-size: 12px;
    color: brown;
    margin-left: 20px;
  }
}
.title_info {
  //  position: relative;
  flex: 1.5;
  padding: 10px 1px;
  .show_lingqu,
  .show_end {
    width: 70%;
    background-color: #fe0038;
    color: #ffffff;
    margin: 0 auto;
    font-size: 0.8rem;
    border-radius: 15px;
    line-height: 16px;
    padding: 0.4rem 0.5rem;
    text-align: center;
  }

  .show_end {
    background: #999999;
    // color: #FFFFFF;
    // margin:0 auto;
    // font-size: 0.8rem;
    // width:15px;
    // line-height:18px;
    // padding: 0.2rem 0.3rem;
  }
  .juedui {
    position: absolute;
    left: 15rem;
    top: 30px;
  }
}
</style>
